package com.zyl.musicdemo.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.zyl.musicdemo.R;
import com.zyl.musicdemo.adapter.AlbumAdapter;
import com.zyl.musicdemo.adapter.SongAdapter;
import com.zyl.musicdemo.bean.HomeBean;
import com.zyl.musicdemo.utils.DataUtils;

public class MainActivity extends BaseActivity {

    RecyclerView recyclerViewAlbum, recyclerViewSong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_1);
        initView();
    }

    private void initView() {
        initNavBar(false, "我的音乐", true);
        recyclerViewAlbum = findViewById(R.id.recyclerView_album);
        recyclerViewSong = findViewById(R.id.recyclerView_song);

        Gson gson = new Gson();
        //拿到文件数据
        String jsonStr = DataUtils.getAssetsFile(this, "DataSource.json");

        HomeBean homeBean = gson.fromJson(jsonStr, HomeBean.class);

        recyclerViewAlbum.setLayoutManager(new GridLayoutManager(this, 3));
        AlbumAdapter albumAdapter = new AlbumAdapter(homeBean.getAlbum());
        recyclerViewAlbum.setAdapter(albumAdapter);

        recyclerViewSong.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        SongAdapter songAdapter = new SongAdapter(homeBean.getHot(), recyclerViewSong);
        recyclerViewSong.setAdapter(songAdapter);

    }


}